\documentclass{article}
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{extramarks}
\usepackage{chngpage}
\usepackage{soul,color}
\usepackage{graphicx,float,wrapfig}
\usepackage{pgf,tikz}
\usepackage[boxruled,vlined]{algorithm2e}
\usepackage[german]{babel}
\usetikzlibrary{%
  arrows,%
  calc,%
  fit,%
  patterns,%
  plotmarks,%
  shapes.geometric,%
  shapes.misc,%
  shapes.symbols,%
  shapes.arrows,%
  shapes.callouts,%
  shapes.multipart,%
  shapes.gates.logic.US,%
  shapes.gates.logic.IEC,%
  er,%
  automata,%
  backgrounds,%
  chains,%
  topaths,%
  trees,%
  petri,%
  mindmap,%
  matrix,%calendar,%
  folding,%
  fadings,%
  through,%
  positioning,%
  scopes,%
  decorations.fractals,%
  decorations.shapes,%
  decorations.text,%
  decorations.pathmorphing,%
  decorations.pathreplacing,%decorations.footprints,%
  decorations.markings,%
  shadows}


% In case you need to adjust margins:
\topmargin=-0.45in      %
\evensidemargin=0in     %
\oddsidemargin=0in      %
\textwidth=6.5in        %
\textheight=9.0in       %
\headsep=0.25in         %

\begin{document}
\begin{spacing}{1.1}

\incmargin{1.8em} \restylealgo{boxruled} \linesnumbered
\begin{algorithm}
\caption{Graph partition\label{algorithm:graph_partition}} \SetLine
\KwIn{A directed graph $G=(V,E)$} \KwOut{A series of subgraphs of
$G$} \BlankLine

$L=\{v:v\in V, outdegree(v) = 0\}$

Invert the directions of all edges in $G$ and get $G'$

\ForEach{$v \in L$}{ DFS on $G'$ and get a subgraph of $G'$ }

Invert the directions of all edges again in each subgraph
\end{algorithm}
\decmargin{1.8em}
\end{spacing}
\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
